//
//  FSMBase.m
//  SpaceStorm
//
//  Created by 祥 雍 on 13-7-21.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//
//  状态机的基类或者接口

#import "FSMBase.h"

@implementation FSMBase

-(void) enter
{
    //子类覆写
    NSAssert(NO, @"FSMBase: enter not supported. Override it");
}

-(void) execute
{
    //子类覆写
    NSAssert(NO, @"FSMBase: execute not supported. Override it");
}

-(void) exit
{
    //子类覆写
    NSAssert(NO, @"FSMBase: exit not supported. Override it");
}

@end


@implementation FSMManagerBase

/**
	逻辑更新状态机
 */
-(void) update
{
    if(_curState != nil)
    {
        [_curState execute];
    }
}

/**
	状态机状态切换
	@param state 要切换的状态
 */
-(void) changeState:(FSMBase*)state
{
    //离开之前的状态
    if(_curState != nil)
    {
        [_curState exit];
        [_curState release];
    }
    
    //进入新的状态
    _curState = state;
    [_curState retain];
    [_curState enter];
}

/**
	释放
 */
-(void) dealloc

{
    if (_curState) 
    {
        [_curState release];
        _curState = nil;
    }
    
    // 不要忘记调用"super dealloc" 
    [super dealloc];
}
@end